package com.class04.dao.impl;

import com.class04.dao.StudentDao;
import com.class04.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/10/31 15:34
 */
@Repository
public class StudentDaoImpl implements StudentDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public List<Student> queryAll() {
        //        BeanPropertyRowMapper帮助我们自动映射列和属性值，
        //        要求列名和属性名一致！
//        不一致 就起别名
//        sql = "select * from students;";
        String sql = "select  id,name,gender,age,class as classes " +
                "from  students;";
        List<Student> studentList = jdbcTemplate.query(sql,
                new BeanPropertyRowMapper<Student>(Student.class));
        System.out.println("studentDao:" + studentList);
        return studentList;
    }
}
